package expressions.slogo;

import java.util.List;
import parsing.Token;
import model.Turtle;

/**
 * Moves the turtle backward a given distance.
 */
@Token(regex = "back|bk")
public class Back extends TurtleCommand
{

    public Back()
    {
        super(1);
    }

    @Override
    protected Double combineResults(List<Double> results, ITurtleContext context)
    {
        Turtle t = context.getTurtle();

        double distance = results.get(0);
        double newx = t.getX() - distance * t.getAngle().cos();
        double newy = t.getY() - distance * t.getAngle().sin();

        t.move(newx, newy);

        return distance;
    }

}
